using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;
using CSP.Model.CSP;

namespace CSP.DataAccess.Mapping
{
    public class ServiceInfoMap : EntityTypeConfiguration<ServiceInfo>
    {
        public ServiceInfoMap()
        {
            // Primary Key
            this.HasKey(t => t.id);

            // Properties
            this.Property(t => t.username)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.title)
                .IsRequired()
                .HasMaxLength(100);

            this.Property(t => t.Description)
                .HasMaxLength(200);

            this.Property(t => t.KeyWords)
                .HasMaxLength(50);

            this.Property(t => t.LastModified)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(8)
                .IsRowVersion();

            // Table & Column Mappings
            this.ToTable("ServiceInfo");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.username).HasColumnName("username");
            this.Property(t => t.title).HasColumnName("title");
            this.Property(t => t.Description).HasColumnName("Description");
            //this.Property(t => t.ServiceTypeId).HasColumnName("ServiceTypeId");
            //this.Property(t => t.AddressId).HasColumnName("AddressId");
            this.Property(t => t.OriginalPrice).HasColumnName("OriginalPrice");
            this.Property(t => t.OriginalPriceUnitld).HasColumnName("OriginalPriceUnitld");
            this.Property(t => t.ClassOfMemberNumber).HasColumnName("ClassOfMemberNumber");
            this.Property(t => t.AgeStart).HasColumnName("AgeStart");
            this.Property(t => t.AgeEnd).HasColumnName("AgeEnd");
            this.Property(t => t.ClassTypeId).HasColumnName("ClassTypeId");
            this.Property(t => t.ClassValidityStart).HasColumnName("ClassValidityStart");
            this.Property(t => t.ClassValidityEnd).HasColumnName("ClassValidityEnd");
            this.Property(t => t.Price).HasColumnName("Price");
            this.Property(t => t.PriceUnitId).HasColumnName("PriceUnitId");
            this.Property(t => t.PriceStart).HasColumnName("PriceStart");
            this.Property(t => t.PriceEnd).HasColumnName("PriceEnd");
            this.Property(t => t.PriceType).HasColumnName("PriceType");
            this.Property(t => t.EnjoyCount).HasColumnName("EnjoyCount");
            this.Property(t => t.SurplusEnjoyCount).HasColumnName("SurplusEnjoyCount");
            this.Property(t => t.KeyWords).HasColumnName("KeyWords");
            this.Property(t => t.Content).HasColumnName("Content");
            this.Property(t => t.img).HasColumnName("img");
            this.Property(t => t.status).HasColumnName("status");
            this.Property(t => t.NewId).HasColumnName("NewId");
            this.Property(t => t.OnLineTime).HasColumnName("OnLineTime");
            this.Property(t => t.LastModified).HasColumnName("LastModified");
            this.Property(t => t.CreateTime).HasColumnName("CreateTime");
            this.Property(t => t.Phone).HasColumnName("Phone");
            

            // Relationships
            //this.HasRequired(t => t.Address)
            //    .WithMany(t => t.ServiceInfoes)
            //    .HasForeignKey(d => d.AddressId);
            this.HasRequired(t => t.ClassType)
                .WithMany(t => t.ServiceInfoes)
                .HasForeignKey(d => d.ClassTypeId);
            this.HasOptional(t => t.PriceUnit)
                .WithMany(t => t.ServiceInfoesOriginal)
                .HasForeignKey(d => d.OriginalPriceUnitld);
            this.HasRequired(t => t.OriginalPriceUnit)
                .WithMany(t => t.ServiceInfoes)
                .HasForeignKey(d => d.PriceUnitId);
            //this.HasRequired(t => t.ServiceType)
            //    .WithMany(t => t.ServiceInfoes)
            //    .HasForeignKey(d => d.ServiceTypeId);

        }
    }
}
